/*
 * Copyright (c) 2024. hallele, Inc All rights reserved.
 */

package cn.hallele.ms.infrastructure.plugin.safety.encryptor;

import cn.hallele.infrastructure.util.SecurityUtil;
import cn.hallele.infrastructure.util.bean.AES;
import lombok.extern.slf4j.Slf4j;
import org.jasypt.encryption.StringEncryptor;

/**
 * spring boot配置文件内容加解密
 *
 * @author anle5
 * @since 2024/9/15 12:37
 */
@Slf4j
public class AESEncryptor implements StringEncryptor {
    private final AES AES;

    public AESEncryptor() {
        this.AES = SecurityUtil.aes();
    }

    /**
     * Encrypt the input message
     *
     * @param message the message to be encrypted
     * @return the result of encryption
     */
    @Override
    public String encrypt(String message) {
        return this.AES.encryptHex(message);
    }

    /**
     * Decrypt an encrypted message
     *
     * @param encryptedMessage the encrypted message to be decrypted
     * @return the result of decryption
     */
    @Override
    public String decrypt(String encryptedMessage) {
        return this.AES.decryptStr(encryptedMessage);
    }
}
